Project 09

Sensors & Simulations: Single axis bending monitoring sensor; Temperature/humidity sensor; Ultrasound sensor

Objective:

To integrate a sensor in a microcontroller board and reading the signal.

  • Materials:
  • (a) CAD software (TinkerCAD) for simulating models;(b) Arduino IDE and clone of Arduino UNO; (c) Adrafruit flex sensor; (d) DHT_11 temeprature (thermistor) and humidity (capacitive) sensor; (e) HC-HR04 ultrasonic (sonar) sensor.

    Simulation:

    At first, I designed the simulation models using the TinkerCAD. Next, I used a breadboard to design my circuit and test it using Arduino Uno.

    Sensor 01: Flex Sensor for Monitoring Bending in 1-axis

  • About the Arduino Uno clone:
  • I am using a clone Arduino Uno that has an ATMEL Mega328P (U-PH 35473D 18473DR) chip. Looking into its datasheet, I found that it is a low power 8-bit AVR family microcontroller operating at a 2.7V to 5.5V. It also has 8 ADC (analog to digital conversion) channels which are 10-bit meaning it is capable of giving digital values ranging between of 0 – 1023 (2^10=1024). These 10 bits are called the max resolution.

  • Resolution of ADC (analog to digital conversion) channels in the Arduino Uno:
  • However, the ATMEL Mega328P built-in Arduino Uno has 6 ADC channels. These 6 ADC channels are at the left corner of the Uno, i.e., A0, A1, A2, A4, A5, which are used for analog input/voltages. It means, each of these channels has the ability to convert analog voltages into 10-bit values at a time ranging between of 0 – 1023 (2^10=1024).



  • Why need ADC channels:
  • ADC is used in applications that require interfacing sensors to the microcontroller chips; because, most of the time the obtained output data from the sensors are analog in nature. Since, microcontrollers only processes digital signals (i.e, the binary numbers 0 and 1), we need to convert the analog signals into digital signals – a role played by the ADC channels.

  • Flex sensor:
  • In this work, a Adafruit Short Flex Sensor [ADA1070] has been used. Based on the datasheet provided, it has a resistance ranging between ~25KΩ (unflexed state) and ~100KΩ (unflexed state). However, after characterization at the lab, it was observed that, the resistance is ~30KΩ at 0o, ~46KΩ at 45o, ~75KΩ at 90o, ~101KΩ at 135o. The dimension (length = 77.57mm/3.054in, width = 6.41mm/0.2525in, and thickness = 0.48mm/0.019in) and weight (=0.27g/0.0095oz) was also noted from the datasheet. It must be noted that the sensor is capable of detecting flex in one direction only, i.e., it is an unidirectional bending sensor.



  • Operating principle and calculation of the flex sensor:
  • The operation and calculation of this flex sensor is based on the working principle of a voltage divider, i.e., applying a voltage source across a series-resistors (Figure and corresponding mathematical equation shown below). In our case, we will provide a 5V input voltage from Arduino and will get the output voltage data, in form of digital readings, from the the Arduino ADC channel A0.



  • Simulation and Coding #1- Checking the flex sensor resolution:

  • Simulation was conducted using the TinkerCAD software. At first, we created and defined the variable for the “Flex_sensor” as it was not built-in into the CAD software. Following that, the remaining part of the sketch was formulated, compiled, and uploaded.

    Video clips



    Code:

    // C++ code
    //
    int Flex_sensor = 0;

    void setup()
    {
    pinMode(A0, INPUT);
    Serial.begin(9600); //Begin serial communication
    }

    void loop()
    {
    Flex_sensor = analogRead(A0);
    Serial.println(Flex_sensor);
    delay(10); // Delay a little bit to improve simulation performance
    }


    Sensor 02: DHT_11 Temperature & Humidity Monitoring Sensor




  • Sensor Specifications:
  • DHT11 is sensor introduced by Adafruit, which is made of two parts: (a) a capacitive humidity sensor and (b) a thermistor (i.e., a thermal resistor - a resistor that changes its resistance with temperature gradient). It operates at 3-5V and has three (in module format) and four pin version. In this study the module was used, which had a VCC pin, ground pin and a signal pin that was connected to the Arduino’s pin no 7.

  • Library download:
  • Before using this sensor module, the library was downloaded in the Arduino IDE (Sketch > Include Library> Manage libraries> “DHT” (on the Search box and install the DHT library from Adafruit).

  • Circuitry, sketch, and experiments:
  • A disposable lighter and wet paper towel was employed during the experiments, and the results were visualized in the serial plotter/monitor. A combination of RGB LED and piezo buzzer can be used to alert the user. Additionally, an LCD (Liquid Crystal Display) can be added to the circuit to display the temperature/humidity values.


    Let's use a lighter and solvent to test the sensitivity to heat and moisture



    Code:

    #include
    dht DHT;
    #define DHT11_PIN 7
    void setup(){
    Serial.begin(9600);
    }
    void loop(){
    int chk = DHT.read11(DHT11_PIN);
    Serial.print("Temperature = ");
    Serial.println(DHT.temperature);
    Serial.print("Humidity = ");
    Serial.println(DHT.humidity);
    delay(100);
    }


    Sensor 03: Ultrasound Distance Measurement Sensor


  • Ultrasound sensor principle:
  • Robotics usually uses different technologies for distance detection and one such strategy is to employ sonar, i.e., the ultrasound technology. The human ear can hear sound only in the 20Hz-20000Hz, and cannot listen to any sound (i.e., vibrating frequency range) below (infra-sound) or above (ultra-sound) this range (as shown in the figure below, collected from “howequipmentworksdotcom”). In the current work, the HC-SR04 (photo collected from wwwdotpiborgdotorg) ultrasound sensor has been used that has four pins: VCC, GRND, Trigger (for transmitter section- the left circular module), and Echo (receiving section- the right circular module).





  • Specifications of ultrasound HC-SR04 distance measuring sensor:
  • From the datasheet, it was found that it works at 40kHz frequency and requires an input voltage of 5V. The maximum drawn current is 20mA. The distance sensing range is 2cm-400cm.

  • Physics behind the calculation:
  • The distance is calculated using the typical law (v=d/t; d=vxt). Since the sensor calculates the duration of the echo, i.e., the travelling time for the sonar to reach the target object and bounce back, in the coding sketch, the duration is divided by 2 to calculate the distance. Also, speed of sound in air at room temperature (20 degree Celsius) is 343 m/s (= 0.0001 * 343 = 0.0343 cm/μs = 1 / 0.0343 = 29.155 μs/cm). Previously, it was reported in a similar project at the Fab Academy that the duty cycle for the trigger signal is 10µS.


    Code:

    // Standard declaration of pins
    int trigPin = 2; // Trigger
    int echoPin = 3; // Echo
    float duration, distancecm, distanceinches;

    void setup() {
    //Serial Port begin
    Serial.begin (9600);
    //Define inputs and outputs
    pinMode(trigPin, OUTPUT); //triggering a sound to bound off an object
    pinMode(echoPin, INPUT); //receiving the sound bounce (echo) from trigger
    }

    void loop() {
    // Standard good measure to include this code ensure a clean pulse signal from the sensor
    digitalWrite(trigPin, LOW);
    delay(5);
    digitalWrite(trigPin, HIGH);
    delay(10);
    digitalWrite(trigPin, LOW);

    //setting receiving pin to INPUT again
    pinMode(echoPin, INPUT);
    //duration (in microseconds) it takes for the sound wave to be sent from sensor to object and return
    duration = pulseIn(echoPin, HIGH);

    // Convert the travel time of sound into distance, distance = time x speed of sound
    distancecm = (duration/2) / 29.1; // or multiply (duration/2) by 0.0343 cm/microseconds
    // distanceinches = (duration/2) / 74; // or multiply (duration/2) by 0.0135 inch/microseconds and 1 cm = 0.393701 in

    //printing the output in readable form
    Serial.print("Distance: ");
    Serial.print(distancecm);
    Serial.print("cm,");
    Serial.println();
    delay(250);
    }